@mimicprotocol/lib-ts 0.0.1-rc.36 → 0.0.1-rc.38

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @mimicprotocol/lib-ts
2
2
 
3
+ ## 0.0.1-rc.38
4
+
5
+ ### Patch Changes
6
+
7
+ - 73e9713: Add getCode function to get the code of an address (Only EVM)
8
+
9
+ ## 0.0.1-rc.37
10
+
11
+ ### Patch Changes
12
+
13
+ - ed2d252: Refactor credentials commands
14
+ - 94ef728: add custom storage
15
+ - 7d2279d: Refactor codegen, compile, build, deploy and test commands and their parameters
16
+
3
17
  ## 0.0.1-rc.36
4
18
 
5
19
  ### Patch Changes
package/index.ts CHANGED
@@ -4,6 +4,7 @@ export * from './src/evm'
4
4
  export * from './src/helpers'
5
5
  export * from './src/intents'
6
6
  export * from './src/log'
7
+ export * from './src/storage'
7
8
  export * from './src/svm'
8
9
  export * from './src/tokens'
9
10
  export * from './src/types'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimicprotocol/lib-ts",
3
- "version": "0.0.1-rc.36",
3
+ "version": "0.0.1-rc.38",
4
4
  "license": "GPL-3.0",
5
5
  "private": false,
6
6
  "type": "module",
@@ -20,7 +20,7 @@ import {
20
20
  TokenPriceQueryResponse,
21
21
  } from './queries'
22
22
  import { BlockchainToken, Token, TokenAmount, USD } from './tokens'
23
- import { Address, BigInt, ChainId, EvmDecodeParam, EvmEncodeParam, Result } from './types'
23
+ import { Address, BigInt, Bytes, ChainId, EvmDecodeParam, EvmEncodeParam, Result } from './types'
24
24
 
25
25
  export namespace environment {
26
26
  @external('environment', '_evmCall')
@@ -219,4 +219,20 @@ export namespace environment {
219
219
  const decoded = BigInt.fromString(decodedResponse)
220
220
  return Result.ok<BigInt, string>(decoded)
221
221
  }
222
+
223
+ /**
224
+ * Returns the code of the target account.
225
+ * @param chainId - Chain id to check code
226
+ * @param target - Address to get code from
227
+ * @returns The code of the target account
228
+ */
229
+ export function getCode(chainId: ChainId, target: Address): Result<Bytes, string> {
230
+ if (chainId === ChainId.SOLANA_MAINNET) return Result.err<Bytes, string>('Solana not supported')
231
+ const data = '0x7e105ce2' + evm.encode([EvmEncodeParam.fromValue('address', target)])
232
+ const response = evmCallQuery(Address.fromHexString(MIMIC_HELPER_ADDRESS), chainId, data)
233
+ if (response.isError) return Result.err<Bytes, string>(response.error)
234
+ const decodedResponse = evm.decode(new EvmDecodeParam('bytes', response.unwrap()))
235
+ const decoded = Bytes.fromHexString(decodedResponse)
236
+ return Result.ok<Bytes, string>(decoded)
237
+ }
222
238
  }
@@ -1,3 +1,5 @@
1
+ /* eslint-disable no-secrets/no-secrets */
2
+
1
3
  export const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'
2
4
  export const EVM_NATIVE_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
3
5
  export const SVM_NATIVE_ADDRESS = 'Nativeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
@@ -12,4 +14,4 @@ export enum ListType {
12
14
  DenyList = 1,
13
15
  }
14
16
 
15
- export const MIMIC_HELPER_ADDRESS = '0x4766EF65d66E8D2d92F3089Ee42e5705e8817FF0'
17
+ export const MIMIC_HELPER_ADDRESS = '0x5cf82cbed1110fc2f75b3413d53abac492931804'
@@ -0,0 +1 @@
1
+ export * from './storage'
@@ -0,0 +1,46 @@
1
+ import { environment } from '../environment'
2
+ import { evm } from '../evm'
3
+ import { MIMIC_HELPER_ADDRESS } from '../helpers'
4
+ import { EvmCall, EvmCallBuilder } from '../intents'
5
+ import { TokenAmount } from '../tokens'
6
+ import { Address, Bytes, ChainId, EvmDecodeParam, EvmEncodeParam, Result } from '../types'
7
+
8
+ const ADDRESS = Address.fromHexString(MIMIC_HELPER_ADDRESS)
9
+ const DEFAULT_CHAIN_ID = ChainId.OPTIMISM
10
+
11
+ export namespace storage {
12
+ export function createSetDataCall(
13
+ smartAccount: Address,
14
+ maxFee: TokenAmount,
15
+ key: string,
16
+ data: Bytes,
17
+ chainId: ChainId = DEFAULT_CHAIN_ID
18
+ ): EvmCall {
19
+ const encodedData = Bytes.fromHexString(
20
+ '0x1c1bbd37' +
21
+ evm.encode([EvmEncodeParam.fromValue('string', Bytes.fromUTF8(key)), EvmEncodeParam.fromValue('bytes', data)])
22
+ )
23
+ return EvmCallBuilder.forChain(chainId)
24
+ .addUser(smartAccount)
25
+ .addMaxFee(maxFee)
26
+ .addCall(ADDRESS, encodedData)
27
+ .build()
28
+ }
29
+
30
+ export function getData(
31
+ smartAccount: Address,
32
+ key: string,
33
+ chainId: ChainId = DEFAULT_CHAIN_ID
34
+ ): Result<Bytes, string> {
35
+ const encodedData =
36
+ '0x53f71fd3' +
37
+ evm.encode([
38
+ EvmEncodeParam.fromValue('address', smartAccount),
39
+ EvmEncodeParam.fromValue('string', Bytes.fromUTF8(key)),
40
+ ])
41
+ const response = environment.evmCallQuery(ADDRESS, chainId, encodedData)
42
+ if (response.isError) return Result.err<Bytes, string>(response.error)
43
+ const decoded = Bytes.fromHexString(evm.decode(new EvmDecodeParam('bytes', response.unwrap())))
44
+ return Result.ok<Bytes, string>(decoded)
45
+ }
46
+ }
@@ -20,7 +20,7 @@ export class ByteArray extends Uint8Array implements Serializable {
20
20
  * The resulting byte array is in little-endian order.
21
21
  */
22
22
  static empty(): ByteArray {
23
- return ByteArray.fromI32(0)
23
+ return new ByteArray(0)
24
24
  }
25
25
 
26
26
  /**