Skip to content

Commit

Permalink
Merge pull request #91 from Premian-Labs/feat/improve-dx
Browse files Browse the repository at this point in the history
Improve DX w/ custom provider optionality and synchronous tx encoding
  • Loading branch information
froggiedev committed Dec 16, 2023
2 parents aac1e40 + af37337 commit e4c70ba
Show file tree
Hide file tree
Showing 19 changed files with 2,520 additions and 1,018 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@premia/v3-sdk",
"version": "2.2.3",
"version": "2.3.0",
"description": "The official SDK for building applications on Premia V3.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
32 changes: 16 additions & 16 deletions src/api/contractAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class ContractAPI extends BaseAPI {
getPoolContract(poolAddress: string, provider?: Provider): IPool {
return IPool__factory.connect(
poolAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -140,7 +140,7 @@ export class ContractAPI extends BaseAPI {
): ISolidStateERC20 {
return ISolidStateERC20__factory.connect(
tokenAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -161,7 +161,7 @@ export class ContractAPI extends BaseAPI {
): IOracleAdapter {
return IOracleAdapter__factory.connect(
oracleAdapterAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -178,7 +178,7 @@ export class ContractAPI extends BaseAPI {
getPoolFactoryContract(provider?: Provider): IPoolFactory {
return IPoolFactory__factory.connect(
this.poolFactoryAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -195,7 +195,7 @@ export class ContractAPI extends BaseAPI {
getPoolDiamondContract(provider?: Provider): IPool {
return IPool__factory.connect(
this.poolDiamondAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -212,7 +212,7 @@ export class ContractAPI extends BaseAPI {
getVaultRegistryContract(provider?: Provider): IVaultRegistry {
return IVaultRegistry__factory.connect(
this.vaultRegistryAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -230,7 +230,7 @@ export class ContractAPI extends BaseAPI {
getVaultContract(vaultAddress: string, provider?: Provider): IVault {
return IVault__factory.connect(
vaultAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -248,7 +248,7 @@ export class ContractAPI extends BaseAPI {
getERC4626Contract(vaultAddress: string, provider?: Provider): IERC4626 {
return IERC4626__factory.connect(
vaultAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -266,7 +266,7 @@ export class ContractAPI extends BaseAPI {
getERC1155Contract(poolAddress: string, provider?: Provider): IERC1155 {
return IERC1155__factory.connect(
poolAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand Down Expand Up @@ -300,7 +300,7 @@ export class ContractAPI extends BaseAPI {
getUserSettingsContract(provider?: Provider): IUserSettings {
return IUserSettings__factory.connect(
this.userSettingsAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -317,7 +317,7 @@ export class ContractAPI extends BaseAPI {
getVxPremiaContract(provider?: Provider): IVxPremia {
return IVxPremia__factory.connect(
this.vxPremiaAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -334,7 +334,7 @@ export class ContractAPI extends BaseAPI {
getReferralContract(provider?: Provider): IReferral {
return IReferral__factory.connect(
this.referralAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -351,7 +351,7 @@ export class ContractAPI extends BaseAPI {
getVaultMiningContract(provider?: Provider): IVaultMining {
return IVaultMining__factory.connect(
this.vaultMiningAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -368,7 +368,7 @@ export class ContractAPI extends BaseAPI {
getOptionRewardContract(provider?: Provider): IOptionReward {
return IOptionReward__factory.connect(
this.optionRewardAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -386,7 +386,7 @@ export class ContractAPI extends BaseAPI {
getOptionPSContract(optionPSAddress: string, provider?: Provider): IOptionPS {
return IOptionPS__factory.connect(
optionPSAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand All @@ -407,7 +407,7 @@ export class ContractAPI extends BaseAPI {
): IDualMining {
return IDualMining__factory.connect(
dualMiningAddress,
provider ?? (this.premia.signer || this.premia.provider)
provider ?? this.premia.signer ?? this.premia.provider
)
}

Expand Down
8 changes: 3 additions & 5 deletions src/api/gasAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ export class GasAPI extends BaseAPI {
* Returns a promise containing the gas price.
* @returns {Promise<bigint>} Promise containing the gas price.
*/
async getGasPrice(): Promise<bigint> {
const price = await (this.premia.provider as JsonRpcProvider).send(
'eth_gasPrice',
[]
)
async getGasPrice(provider?: JsonRpcProvider): Promise<bigint> {
const _provider = provider ?? (this.premia.provider as JsonRpcProvider)
const price = await _provider.send('eth_gasPrice', [])
return BigInt(price)
}
}

0 comments on commit e4c70ba

Please sign in to comment.