-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add v1 publicActionsChildChain
- Loading branch information
1 parent
a8bab3b
commit 7e7580e
Showing
4 changed files
with
308 additions
and
0 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
30 changes: 30 additions & 0 deletions
30
src/decorators/__snapshots__/publicActionsChildChain.unit.test.ts.snap
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,30 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Getters > [getAllChainOwners] Should return all chain owners 1`] = `[]`; | ||
|
||
exports[`Getters > [getGasAccountingParams] Should return gas accounting params 1`] = ` | ||
[ | ||
7000000n, | ||
32000000n, | ||
32000000n, | ||
] | ||
`; | ||
|
||
exports[`Getters > [getInfraFeeAccount] Should return infra fee account 1`] = `"0xbF5041Fc07E1c866D15c749156657B8eEd0fb649"`; | ||
|
||
exports[`Getters > [getMinimumGasPrice] Should return minimum gas price 1`] = `10000000n`; | ||
|
||
exports[`Getters > [getNetworkFeeAccount] Should return network fee account 1`] = `"0x32e7AF5A8151934F3787d0cD59EB6EDd0a736b1d"`; | ||
|
||
exports[`Getters > [getParentBaseFeeEstimate] Should return parent base fee estimate 1`] = `106354669n`; | ||
|
||
exports[`Getters > [getParentRewardRate] Should return parent reward rate 1`] = `0n`; | ||
|
||
exports[`Getters > [getParentRewardRecipient] Should return parent reward recipient 1`] = `"0x2E041280627800801E90E9Ac83532fadb6cAd99A"`; | ||
|
||
exports[`Getters > [getScheduledUpgrade] Should return scheduled upgrade 1`] = ` | ||
{ | ||
"arbosVersion": 0n, | ||
"scheduledForTimestamp": 0n, | ||
} | ||
`; |
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,178 @@ | ||
import { Chain, PublicClient, Transport } from 'viem'; | ||
|
||
// Getters | ||
import { | ||
getAllChainOwners, | ||
GetAllChainOwnersParameters, | ||
GetAllChainOwnersReturnType, | ||
} from '../actions/getAllChainOwners'; | ||
import { | ||
getInfraFeeAccount, | ||
GetInfraFeeAccountParameters, | ||
GetInfraFeeAccountReturnType, | ||
} from '../actions/getInfraFeeAccount'; | ||
import { | ||
getNetworkFeeAccount, | ||
GetNetworkFeeAccountParameters, | ||
GetNetworkFeeAccountReturnType, | ||
} from '../actions/getNetworkFeeAccount'; | ||
import { | ||
getScheduledUpgrade, | ||
GetScheduledUpgradeParameters, | ||
GetScheduledUpgradeReturnType, | ||
} from '../actions/getScheduledUpgrade'; | ||
import { | ||
isChainOwner, | ||
IsChainOwnerParameters, | ||
IsChainOwnerReturnType, | ||
} from '../actions/isChainOwner'; | ||
import { | ||
getGasAccountingParams, | ||
GetGasAccountingParamsParameters, | ||
GetGasAccountingParamsReturnType, | ||
} from '../actions/getGasAccountingParams'; | ||
import { | ||
getMinimumGasPrice, | ||
GetMinimumGasPriceParameters, | ||
GetMinimumGasPriceReturnType, | ||
} from '../actions/getMinimumGasPrice'; | ||
import { | ||
getParentBaseFeeEstimate, | ||
GetParentBaseFeeEstimateParameters, | ||
GetParentBaseFeeEstimateReturnType, | ||
} from '../actions/getParentBaseFeeEstimate'; | ||
import { | ||
getParentRewardRate, | ||
GetParentRewardRateParameters, | ||
GetParentRewardRateReturnType, | ||
} from '../actions/getParentRewardRate'; | ||
import { | ||
getParentRewardRecipient, | ||
GetParentRewardRecipientParameters, | ||
GetParentRewardRecipientReturnType, | ||
} from '../actions/getParentRewardRecipient'; | ||
// Setters | ||
import { | ||
addChainOwner, | ||
AddChainOwnerParameters, | ||
AddChainOwnerReturnType, | ||
} from '../actions/addChainOwner'; | ||
import { | ||
removeChainOwner, | ||
RemoveChainOwnerParameters, | ||
RemoveChainOwnerReturnType, | ||
} from '../actions/removeChainOwner'; | ||
import { | ||
setMaxTxGasLimit, | ||
SetMaxTxGasLimitParameters, | ||
SetMaxTxGasLimitReturnType, | ||
} from '../actions/setMaxTxGasLimit'; | ||
import { | ||
setParentPricePerUnit, | ||
SetParentPricePerUnitParameters, | ||
SetParentPricePerUnitReturnType, | ||
} from '../actions/setParentPricePerUnit'; | ||
import { | ||
setParentPricingRewardRate, | ||
SetParentPricingRewardRateParameters, | ||
SetParentPricingRewardRateReturnType, | ||
} from '../actions/setParentPricingRewardRate'; | ||
import { | ||
setParentPricingRewardRecipient, | ||
SetParentPricingRewardRecipientParameters, | ||
SetParentPricingRewardRecipientReturnType, | ||
} from '../actions/setParentPricingRewardRecipient'; | ||
import { | ||
setSpeedLimit, | ||
SetSpeedLimitParameters, | ||
SetSpeedLimitReturnType, | ||
} from '../actions/setSpeedLimit'; | ||
|
||
export type PublicActionsChildChain = { | ||
// Getters | ||
getAllChainOwners: ( | ||
parameters: GetAllChainOwnersParameters, | ||
) => Promise<GetAllChainOwnersReturnType>; | ||
getInfraFeeAccount: ( | ||
parameters: GetInfraFeeAccountParameters, | ||
) => Promise<GetInfraFeeAccountReturnType>; | ||
getNetworkFeeAccount: ( | ||
parameters: GetNetworkFeeAccountParameters, | ||
) => Promise<GetNetworkFeeAccountReturnType>; | ||
getScheduledUpgrade: ( | ||
parameters: GetScheduledUpgradeParameters, | ||
) => Promise<GetScheduledUpgradeReturnType>; | ||
isChainOwner: (parameters: IsChainOwnerParameters) => Promise<IsChainOwnerReturnType>; | ||
getGasAccountingParams: ( | ||
parameters: GetGasAccountingParamsParameters, | ||
) => Promise<GetGasAccountingParamsReturnType>; | ||
getMinimumGasPrice: ( | ||
parameters: GetMinimumGasPriceParameters, | ||
) => Promise<GetMinimumGasPriceReturnType>; | ||
getParentBaseFeeEstimate: ( | ||
parameters: GetParentBaseFeeEstimateParameters, | ||
) => Promise<GetParentBaseFeeEstimateReturnType>; | ||
getParentRewardRate: ( | ||
parameters: GetParentRewardRateParameters, | ||
) => Promise<GetParentRewardRateReturnType>; | ||
getParentRewardRecipient: ( | ||
parameters: GetParentRewardRecipientParameters, | ||
) => Promise<GetParentRewardRecipientReturnType>; | ||
// Setters | ||
addChainOwner: (parameters: AddChainOwnerParameters) => Promise<AddChainOwnerReturnType>; | ||
removeChainOwner: (parameters: RemoveChainOwnerParameters) => Promise<RemoveChainOwnerReturnType>; | ||
setMaxTxGasLimit: (parameters: SetMaxTxGasLimitParameters) => Promise<SetMaxTxGasLimitReturnType>; | ||
setParentPricePerUnit: ( | ||
parameters: SetParentPricePerUnitParameters, | ||
) => Promise<SetParentPricePerUnitReturnType>; | ||
setParentPricingRewardRate: ( | ||
parameters: SetParentPricingRewardRateParameters, | ||
) => Promise<SetParentPricingRewardRateReturnType>; | ||
setParentPricingRewardRecipient: ( | ||
parameters: SetParentPricingRewardRecipientParameters, | ||
) => Promise<SetParentPricingRewardRecipientReturnType>; | ||
setSpeedLimit: (parameters: SetSpeedLimitParameters) => Promise<SetSpeedLimitReturnType>; | ||
}; | ||
|
||
/** | ||
* Public actions for child chain | ||
* | ||
* @example | ||
* import { createPublicClient, http } from 'viem' | ||
* import { publicActionsChildChain } from '@arbitrum/orbit-sdk' | ||
* | ||
* export const publicClientChildChain = createPublicClient({ | ||
* chain: orbitChain, | ||
* transport: http(), | ||
* }).extend(publicActionsChildChain()) | ||
* | ||
* const isAChainOwner = await publicClientChildChain.isChainOwner({ address: zeroAddress }) | ||
*/ | ||
export function publicActionsChildChain< | ||
TTransport extends Transport = Transport, | ||
TChain extends Chain | undefined = Chain | undefined, | ||
>() { | ||
return (client: PublicClient<TTransport, TChain>) => { | ||
return { | ||
// Getters | ||
getAllChainOwners: () => getAllChainOwners(client), | ||
getInfraFeeAccount: () => getInfraFeeAccount(client), | ||
getNetworkFeeAccount: () => getNetworkFeeAccount(client), | ||
getScheduledUpgrade: () => getScheduledUpgrade(client), | ||
isChainOwner: (args) => isChainOwner(client, args), | ||
getGasAccountingParams: () => getGasAccountingParams(client), | ||
getMinimumGasPrice: () => getMinimumGasPrice(client), | ||
getParentBaseFeeEstimate: () => getParentBaseFeeEstimate(client), | ||
getParentRewardRate: () => getParentRewardRate(client), | ||
getParentRewardRecipient: () => getParentRewardRecipient(client), | ||
// Setters | ||
addChainOwner: (args) => addChainOwner(client, args), | ||
removeChainOwner: (args) => removeChainOwner(client, args), | ||
setMaxTxGasLimit: (args) => setMaxTxGasLimit(client, args), | ||
setParentPricePerUnit: (args) => setParentPricePerUnit(client, args), | ||
setParentPricingRewardRate: (args) => setParentPricingRewardRate(client, args), | ||
setParentPricingRewardRecipient: (args) => setParentPricingRewardRecipient(client, args), | ||
setSpeedLimit: (args) => setSpeedLimit(client, args), | ||
} satisfies PublicActionsChildChain; | ||
}; | ||
} |
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,72 @@ | ||
import { it, expect, describe } from 'vitest'; | ||
|
||
import { createPublicClient, http, zeroAddress } from 'viem'; | ||
import { publicActionsChildChain } from './publicActionsChildChain'; | ||
import { arbitrum } from 'viem/chains'; | ||
import { xai } from '../chains'; | ||
|
||
const client = createPublicClient({ | ||
chain: arbitrum, | ||
transport: http(), | ||
}).extend(publicActionsChildChain()); | ||
|
||
describe('Getters', () => { | ||
it('[getAllChainOwners] Should return all chain owners', async () => { | ||
const allChainOwners = await client.getAllChainOwners(); | ||
expect(allChainOwners).toMatchSnapshot(); | ||
}); | ||
|
||
it('[getInfraFeeAccount] Should return infra fee account', async () => { | ||
const infraFeeAccount = await client.getInfraFeeAccount(); | ||
expect(infraFeeAccount).toMatchSnapshot(); | ||
}); | ||
|
||
it('[getNetworkFeeAccount] Should return network fee account', async () => { | ||
const networkFeeAccount = await client.getNetworkFeeAccount(); | ||
expect(networkFeeAccount).toMatchSnapshot(); | ||
}); | ||
|
||
it('[getScheduledUpgrade] Should return scheduled upgrade', async () => { | ||
const scheduledUpgrade = await client.getScheduledUpgrade(); | ||
expect(scheduledUpgrade).toMatchSnapshot(); | ||
}); | ||
|
||
it('[isChainOwner] Should return if an address is a chain owner', async () => { | ||
const xaiClient = createPublicClient({ | ||
chain: xai, | ||
transport: http(), | ||
}).extend(publicActionsChildChain()); | ||
const isZeroAddressChainOwner = await xaiClient.isChainOwner({ address: zeroAddress }); | ||
expect(isZeroAddressChainOwner).toBeFalsy(); | ||
const allChainOwners = await xaiClient.getAllChainOwners(); | ||
const isChainOwner = await xaiClient.isChainOwner({ | ||
address: allChainOwners[0], | ||
}); | ||
expect(isChainOwner).toBeTruthy(); | ||
}); | ||
|
||
it('[getGasAccountingParams] Should return gas accounting params', async () => { | ||
const gasAccountingParams = await client.getGasAccountingParams(); | ||
expect(gasAccountingParams).toMatchSnapshot(); | ||
}); | ||
|
||
it('[getMinimumGasPrice] Should return minimum gas price', async () => { | ||
const minimumGasPrice = await client.getMinimumGasPrice(); | ||
expect(minimumGasPrice).toMatchSnapshot(); | ||
}); | ||
|
||
it('[getParentBaseFeeEstimate] Should return parent base fee estimate', async () => { | ||
const parentBaseFeeEstimate = await client.getParentBaseFeeEstimate(); | ||
expect(parentBaseFeeEstimate).toMatchSnapshot(); | ||
Check failure on line 60 in src/decorators/publicActionsChildChain.unit.test.ts GitHub Actions / Test (Unit)src/decorators/publicActionsChildChain.unit.test.ts > Getters > [getParentBaseFeeEstimate] Should return parent base fee estimate
|
||
}); | ||
|
||
it('[getParentRewardRate] Should return parent reward rate', async () => { | ||
const parentRewardRate = await client.getParentRewardRate(); | ||
expect(parentRewardRate).toMatchSnapshot(); | ||
}); | ||
|
||
it('[getParentRewardRecipient] Should return parent reward recipient', async () => { | ||
const parentRewardRecipient = await client.getParentRewardRecipient(); | ||
expect(parentRewardRecipient).toMatchSnapshot(); | ||
}); | ||
}); |