Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup all LDNFT related contracts #26

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/contracts/configs/BinanceTest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,37 @@ export const BinanceTestChainConfig: TChainConfig = {
lockDealNFT: {
address: "0x522B12eB0a9807b6d13717089124ce9420d495AC",
nameVersion: "[email protected]"
},
vaultManager: {
address: "0xe8bdd7C33eA8783176Fd0C8Df7B255cF64fEEFda",
nameVersion: "[email protected]"
},
dealProvider: {
address: "0x5b007F06CB9708A1E419Fe936aE826C4eba21a8d",
nameVersion: "[email protected]"
},
lockDealProvider: {
address: "0x39f5487929e68CC0242905d1f6e97d0C0992cb77",
nameVersion: "[email protected]"
},
timedDealProvider: {
address: "0x3D0Ca2259046D6660937864b67287269268D2b61",
nameVersion: "[email protected]"
},
collateralProvider: {
address: "0xE63De121ca8Fc1C540DBCd432d1c9D3A5cDEB94A",
nameVersion: "[email protected]"
},
refundProvider: {
address: "0x9a3188e32Bda4C47491186b7DBd412854A8e3921",
nameVersion: "[email protected]"
},
simpleBuilder: {
address: "0x4338C2706052930C065CD7fe396f4E70494Cf7B3",
nameVersion: "[email protected]"
},
simpleRefundBuilder: {
address: "0x9c39a03459522185a1598D4ad2a9cCCCB0F5Ff8f",
nameVersion: "[email protected]"
}
}
135 changes: 119 additions & 16 deletions src/poolz/ThePoolz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
public lockedDealV2: IThePoolzInterface["lockedDealV2"]
public delayVaultContract: IThePoolzInterface["delayVaultContract"]
public lockDealNFTContract: IThePoolzInterface["lockDealNFTContract"]
public vaultManagerContract: IThePoolzInterface["vaultManagerContract"]
public dealProviderContract: IThePoolzInterface["dealProviderContract"]
public lockDealProviderContract: IThePoolzInterface["lockDealProviderContract"]
public timedDealProviderContract: IThePoolzInterface["timedDealProviderContract"]
public collateralProviderContract: IThePoolzInterface["collateralProviderContract"]
public refundProviderContract: IThePoolzInterface["refundProviderContract"]
public simpleBuilderContract: IThePoolzInterface["simpleBuilderContract"]
public simpleRefundBuilderContract: IThePoolzInterface["simpleRefundBuilderContract"]

#provider: typeof Web3.givenProvider
#contracts = new Map<string, Contract>()
Expand Down Expand Up @@ -68,47 +76,57 @@
this.balance = await this.web3.eth.getBalance(this.account)
}

private async initPoolzContracts() {
const chainConfig = AVAILABLE_CHAINS.get(this.chainId)
if (!chainConfig) return
const { poolzTokenAddress, poolzAddress, whiteListAddress, lockedDealV2, poolzBackWithdraw, signUpAddress, delayVault, lockDealNFT } =
chainConfig
const {
poolzTokenAddress,
poolzAddress,
whiteListAddress,
lockedDealV2,
poolzBackWithdraw,
signUpAddress,
delayVault,
lockDealNFT,
vaultManager,
dealProvider,
lockDealProvider,
timedDealProvider,
collateralProvider,
refundProvider,
simpleBuilder,
simpleRefundBuilder
} = chainConfig

this.poolzTokenAddress = poolzTokenAddress

if (poolzAddress) {
const poolzContract = new this.web3.eth.Contract(POOLZ.abi as AbiItem[], poolzAddress)
poolzContract.options.address = poolzAddress
// deprecated
this.poolzAddress = poolzAddress
// deprecated
this.poolzContract = poolzContract
this.CPoolx = {
address: poolzAddress,
nameVersion: "CPoolx",
contract: poolzContract
}
}
if (whiteListAddress) {
const whiteListContract = new this.web3.eth.Contract(WhiteList.abi as AbiItem[], whiteListAddress)
// deprecated
this.whiteListAddress = whiteListAddress
// deprecated
this.whiteListContract = whiteListContract
this.CWhiteList = {
address: whiteListAddress,
nameVersion: "CWhiteList",
contract: whiteListContract
}
}
if (lockedDealV2) {
try {
const abi = await this.fetchContractAbi(lockedDealV2.nameVersion)
this.lockedDealV2 = { ...lockedDealV2, contract: new this.web3.eth.Contract(abi as AbiItem[], lockedDealV2.address) }
} catch (e) {}
}
if (poolzBackWithdraw) {
this.poolzBackWithdraw = Array.isArray(poolzBackWithdraw) ? poolzBackWithdraw : [poolzBackWithdraw]

Check notice on line 129 in src/poolz/ThePoolz.ts

View check run for this annotation

codefactor.io / CodeFactor

src/poolz/ThePoolz.ts#L79-L129

Complex Method
this.poolzBackWithdrawContract = this.poolzBackWithdraw.map((address) => new this.web3.eth.Contract(POOLZ.abi as AbiItem[], address))
}
if (signUpAddress) {
Expand All @@ -121,17 +139,102 @@
contract: signUpContract
}
}

const abifetchPromises = []

if (lockedDealV2) {
abifetchPromises.push(this.fetchContractAbi(lockedDealV2.nameVersion)
.then(abi => {
this.lockedDealV2 = { ...lockedDealV2, contract: new this.web3.eth.Contract(abi as AbiItem[], lockedDealV2.address) }
})
.catch(e => {console.error(e)})
);
}
if (delayVault) {
try {
const abi = await this.fetchContractAbi(delayVault.nameVersion)
this.delayVaultContract = { ...delayVault, contract: new this.web3.eth.Contract(abi as AbiItem[], delayVault.address) }
} catch (e) {}
abifetchPromises.push(this.fetchContractAbi(delayVault.nameVersion)
.then(abi => {
this.delayVaultContract = { ...delayVault, contract: new this.web3.eth.Contract(abi as AbiItem[], delayVault.address) }
})
.catch(e => {console.error(e)})
);
}
if (lockDealNFT) {
try {
const abi = await this.fetchContractAbi(lockDealNFT.nameVersion)
this.lockDealNFTContract = { ...lockDealNFT, contract: new this.web3.eth.Contract(abi as AbiItem[], lockDealNFT.address) }
} catch (e) {}
abifetchPromises.push(this.fetchContractAbi(lockDealNFT.nameVersion)
.then(abi => {
this.lockDealNFTContract = { ...lockDealNFT, contract: new this.web3.eth.Contract(abi as AbiItem[], lockDealNFT.address) }
})
.catch(e => {console.error(e)})
);
}
if (vaultManager) {
abifetchPromises.push(this.fetchContractAbi(vaultManager.nameVersion)
.then(abi => {
this.vaultManagerContract = { ...vaultManager, contract: new this.web3.eth.Contract(abi as AbiItem[], vaultManager.address) }
})
.catch(e => {console.error(e)})
);
}
if (dealProvider) {
abifetchPromises.push(this.fetchContractAbi(dealProvider.nameVersion)
.then(abi => {
this.dealProviderContract = { ...dealProvider, contract: new this.web3.eth.Contract(abi as AbiItem[], dealProvider.address) }
})
.catch(e => {console.error(e)})
);
}
if (lockDealProvider) {
abifetchPromises.push(this.fetchContractAbi(lockDealProvider.nameVersion)
.then(abi => {
this.lockDealProviderContract = { ...lockDealProvider, contract: new this.web3.eth.Contract(abi as AbiItem[], lockDealProvider.address) }
})
.catch(e => {console.error(e)})
);
}
if (timedDealProvider) {
abifetchPromises.push(this.fetchContractAbi(timedDealProvider.nameVersion)
.then(abi => {
this.timedDealProviderContract = { ...timedDealProvider, contract: new this.web3.eth.Contract(abi as AbiItem[], timedDealProvider.address) }
})
.catch(e => {console.error(e)})
);
}
if (collateralProvider) {
abifetchPromises.push(this.fetchContractAbi(collateralProvider.nameVersion)
.then(abi => {
this.collateralProviderContract = { ...collateralProvider, contract: new this.web3.eth.Contract(abi as AbiItem[], collateralProvider.address) }
})
.catch(e => {console.error(e)})
);
}
if (refundProvider) {
abifetchPromises.push(this.fetchContractAbi(refundProvider.nameVersion)
.then(abi => {
this.refundProviderContract = { ...refundProvider, contract: new this.web3.eth.Contract(abi as AbiItem[], refundProvider.address) }
})
.catch(e => {console.error(e)})
);
}
if (simpleBuilder) {
abifetchPromises.push(this.fetchContractAbi(simpleBuilder.nameVersion)
.then(abi => {
this.simpleBuilderContract = { ...simpleBuilder, contract: new this.web3.eth.Contract(abi as AbiItem[], simpleBuilder.address) }
})
.catch(e => {console.error(e)})
);
}
if (simpleRefundBuilder) {
abifetchPromises.push(this.fetchContractAbi(simpleRefundBuilder.nameVersion)
.then(abi => {
this.simpleRefundBuilderContract = { ...simpleRefundBuilder, contract: new this.web3.eth.Contract(abi as AbiItem[], simpleRefundBuilder.address) }
})
.catch(e => {console.error(e)})
);
}

try {
await Promise.allSettled(abifetchPromises)
} catch (e) {
console.error(e)
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/types/IThePoolzInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ export interface IThePoolzInterface {
poolzTokenAddress?: string
delayVaultContract?: IContractInfo
lockDealNFTContract?: IContractInfo
vaultManagerContract?: IContractInfo
dealProviderContract?: IContractInfo
lockDealProviderContract?: IContractInfo
timedDealProviderContract?: IContractInfo
collateralProviderContract?: IContractInfo
refundProviderContract?: IContractInfo
simpleBuilderContract?: IContractInfo
simpleRefundBuilderContract?: IContractInfo

getChaincoinInfo(k?: number): Promise<IChainInfo | undefined>
ERC20Balance(token: string, account: string): Promise<string>
Expand Down Expand Up @@ -108,6 +116,14 @@ export interface IChainConfig {
poolzTokenAddress: IThePoolzInterface["poolzTokenAddress"]
delayVault: Omit<NonNullable<IThePoolzInterface["delayVaultContract"]>, "contract">
lockDealNFT: Omit<NonNullable<IThePoolzInterface["lockDealNFTContract"]>, "contract">
vaultManager: Omit<NonNullable<IThePoolzInterface["vaultManagerContract"]>, "contract">
dealProvider: Omit<NonNullable<IThePoolzInterface["dealProviderContract"]>, "contract">
lockDealProvider: Omit<NonNullable<IThePoolzInterface["lockDealProviderContract"]>, "contract">
timedDealProvider: Omit<NonNullable<IThePoolzInterface["timedDealProviderContract"]>, "contract">
collateralProvider: Omit<NonNullable<IThePoolzInterface["collateralProviderContract"]>, "contract">
refundProvider: Omit<NonNullable<IThePoolzInterface["refundProviderContract"]>, "contract">
simpleBuilder: Omit<NonNullable<IThePoolzInterface["simpleBuilderContract"]>, "contract">
simpleRefundBuilder: Omit<NonNullable<IThePoolzInterface["simpleRefundBuilderContract"]>, "contract">
}

export type TChainConfig = Partial<IChainConfig>