@mimicprotocol/lib-ts 0.0.1-rc.9 → 0.0.1

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/README.md +7 -7
  3. package/constants.d.ts +1 -0
  4. package/constants.js +1 -0
  5. package/index.ts +3 -0
  6. package/package.json +18 -4
  7. package/src/chains/Arbitrum.ts +14 -0
  8. package/src/chains/Avalanche.ts +15 -0
  9. package/src/chains/BNB.ts +15 -0
  10. package/src/chains/Base.ts +14 -0
  11. package/src/chains/BaseSepolia.ts +7 -0
  12. package/src/chains/Ethereum.ts +7 -7
  13. package/src/chains/Gnosis.ts +14 -0
  14. package/src/chains/Optimism.ts +7 -7
  15. package/src/chains/Polygon.ts +10 -7
  16. package/src/chains/Sonic.ts +13 -0
  17. package/src/chains/index.ts +7 -0
  18. package/src/context/Context.ts +102 -7
  19. package/src/environment.ts +165 -53
  20. package/src/evm.ts +5 -4
  21. package/src/helpers/BorshDeserializer.ts +133 -0
  22. package/src/helpers/consensus.ts +35 -0
  23. package/src/helpers/constants.ts +7 -1
  24. package/src/helpers/index.ts +5 -0
  25. package/src/helpers/math.ts +20 -0
  26. package/src/helpers/serialize.ts +5 -125
  27. package/src/helpers/strings.ts +82 -5
  28. package/src/intents/Call/EvmCall.ts +283 -0
  29. package/src/intents/Call/SvmCall.ts +278 -0
  30. package/src/intents/Call/index.ts +2 -0
  31. package/src/intents/Intent.ts +178 -5
  32. package/src/intents/Swap.ts +136 -44
  33. package/src/intents/Transfer.ts +103 -58
  34. package/src/log.ts +83 -0
  35. package/src/queries/EvmCallQuery.ts +43 -0
  36. package/src/queries/QueryResponse.ts +26 -0
  37. package/src/queries/RelevantTokensQuery.ts +82 -0
  38. package/src/queries/SubgraphQuery.ts +50 -0
  39. package/src/queries/SvmAccountsInfoQuery.ts +65 -0
  40. package/src/queries/TokenPriceQuery.ts +47 -0
  41. package/src/queries/index.ts +6 -1
  42. package/src/storage/index.ts +1 -0
  43. package/src/storage/storage.ts +46 -0
  44. package/src/svm.ts +27 -0
  45. package/src/tokens/BlockchainToken.ts +108 -0
  46. package/src/tokens/DenominationToken.ts +70 -0
  47. package/src/tokens/ERC20Token.ts +192 -0
  48. package/src/tokens/SPLToken.ts +162 -0
  49. package/src/tokens/Token.ts +55 -155
  50. package/src/tokens/TokenAmount.ts +72 -30
  51. package/src/tokens/TokenProvider.ts +54 -0
  52. package/src/tokens/Tokens.ts +186 -0
  53. package/src/tokens/USD.ts +9 -6
  54. package/src/tokens/index.ts +6 -0
  55. package/src/types/Address.ts +86 -14
  56. package/src/types/BigInt.ts +14 -22
  57. package/src/types/ByteArray.ts +41 -3
  58. package/src/types/Bytes.ts +7 -0
  59. package/src/types/ChainId.ts +9 -1
  60. package/src/types/Option.ts +35 -0
  61. package/src/types/Result.ts +68 -0
  62. package/src/types/TriggerType.ts +4 -0
  63. package/src/types/evm/EvmDecodeParam.ts +7 -0
  64. package/src/types/evm/EvmEncodeParam.ts +31 -0
  65. package/src/types/evm/index.ts +2 -0
  66. package/src/types/index.ts +8 -2
  67. package/src/types/svm/SvmAccountInfo.ts +32 -0
  68. package/src/types/svm/SvmAccountMeta.ts +28 -0
  69. package/src/types/svm/SvmFindProgramAddress.ts +32 -0
  70. package/src/types/svm/SvmMint.ts +44 -0
  71. package/src/types/svm/SvmPdaSeed.ts +19 -0
  72. package/src/types/svm/SvmTokenMetadataData.ts +29 -0
  73. package/src/types/svm/index.ts +5 -0
  74. package/src/intents/Call.ts +0 -238
  75. package/src/queries/Call.ts +0 -16
  76. package/src/types/EvmDecodeParam.ts +0 -30
  77. package/src/types/EvmEncodeParam.ts +0 -54
package/CHANGELOG.md ADDED
@@ -0,0 +1,134 @@
1
+ # @mimicprotocol/lib-ts
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 54f7344: Add Polygon, Avalanche, and BNB chain support
8
+ - 9a993b0: Add getNativeBalance
9
+ - 8aa883e: Bump sdk and runner versions
10
+ - 32adf4f: Fix ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING for new node versions
11
+ - 72bb607: Fix relevant tokens query price filter
12
+ - 8853afe: Fix clashing Result import
13
+ - 2bbe278: update eslint config
14
+ - 1e48dff: Bump runner-node to version 0.0.1-rc.8
15
+ - da39b85: Added Tokens class
16
+ - 9530e1c: Revert test command directory change
17
+ - 4a47218: Add function filter to codegen
18
+ - 426a4fe: Environment refactored
19
+ - 73e9713: Add getCode function to get the code of an address (Only EVM)
20
+ - 52b567d: Align oracle types naming convention
21
+ - 6a4fb70: rename to use functions
22
+ - 7657416: Add address and chain to event data
23
+ - e1277c7: Refactor Result to use unwrap instead of value
24
+ - 73a7900: Add login, logout and profiles commands
25
+ - 323663a: Change directory to positional argument in init and test command
26
+ - 213f37f: Fix class names overlapping
27
+ - 73a9cde: Fix npx init
28
+ - faac37c: Ensure early returns in favor of else blocks
29
+ - 0a6602a: Handle oracle query errors
30
+ - 48352fe: Add runner target on compilation
31
+ - ed2d252: Refactor credentials commands
32
+ - 21aba8d: Improve mocks error messages
33
+ - 94ef728: add custom storage
34
+ - 5c8c562: Fix MockConfig validator
35
+ - d455822: Bump SDK version
36
+ - 7d2279d: Refactor codegen, compile, build, deploy and test commands and their parameters
37
+
38
+ ## 0.0.1-rc.41
39
+
40
+ ### Patch Changes
41
+
42
+ - 54f7344: Add Polygon, Avalanche, and BNB chain support
43
+
44
+ ## 0.0.1-rc.40
45
+
46
+ ### Patch Changes
47
+
48
+ - 32adf4f: Fix ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING for new node versions
49
+ - 2bbe278: update eslint config
50
+
51
+ ## 0.0.1-rc.39
52
+
53
+ ### Patch Changes
54
+
55
+ - 48352fe: Add runner target on compilation
56
+
57
+ ## 0.0.1-rc.38
58
+
59
+ ### Patch Changes
60
+
61
+ - 73e9713: Add getCode function to get the code of an address (Only EVM)
62
+
63
+ ## 0.0.1-rc.37
64
+
65
+ ### Patch Changes
66
+
67
+ - ed2d252: Refactor credentials commands
68
+ - 94ef728: add custom storage
69
+ - 7d2279d: Refactor codegen, compile, build, deploy and test commands and their parameters
70
+
71
+ ## 0.0.1-rc.36
72
+
73
+ ### Patch Changes
74
+
75
+ - 6a4fb70: rename to use functions
76
+
77
+ ## 0.0.1-rc.35
78
+
79
+ ### Patch Changes
80
+
81
+ - 9a993b0: Add getNativeBalance
82
+ - da39b85: Added Tokens class
83
+ - 426a4fe: Environment refactored
84
+
85
+ ## 0.0.1-rc.34
86
+
87
+ ### Patch Changes
88
+
89
+ - 73a7900: Add login, logout and profiles commands
90
+ - d455822: Bump SDK version
91
+
92
+ ## 0.0.1-rc.33
93
+
94
+ ### Patch Changes
95
+
96
+ - 9530e1c: Revert test command directory change
97
+ - 21aba8d: Improve mocks error messages
98
+ - 5c8c562: Fix MockConfig validator
99
+
100
+ ## 0.0.1-rc.32
101
+
102
+ ### Patch Changes
103
+
104
+ - 8853afe: Fix clashing Result import
105
+ - e1277c7: Refactor Result to use unwrap instead of value
106
+ - 323663a: Change directory to positional argument in init and test command
107
+ - faac37c: Ensure early returns in favor of else blocks
108
+
109
+ ## 0.0.1-rc.31
110
+
111
+ ### Patch Changes
112
+
113
+ - 1e48dff: Bump runner-node to version 0.0.1-rc.8
114
+
115
+ ## 0.0.1-rc.30
116
+
117
+ ### Patch Changes
118
+
119
+ - 213f37f: Fix class names overlapping
120
+
121
+ ## 0.0.1-rc.29
122
+
123
+ ### Patch Changes
124
+
125
+ - 72bb607: Fix relevant tokens query price filter
126
+ - 52b567d: Align oracle types naming convention
127
+ - 73a9cde: Fix npx init
128
+ - 0a6602a: Handle oracle query errors
129
+
130
+ ## 0.0.1-rc.28
131
+
132
+ ### Patch Changes
133
+
134
+ - 7657416: Add address and chain to event data
package/README.md CHANGED
@@ -25,11 +25,11 @@
25
25
 
26
26
  ## Content
27
27
 
28
- This package provides a lightweight standard library for writing Mimic Protocol tasks in AssemblyScript. It includes:
28
+ This package provides a lightweight standard library for writing Mimic Protocol functions in AssemblyScript. It includes:
29
29
 
30
30
  - Typed primitives to interact with oracles and contracts
31
31
  - Safe and minimal bindings for blockchain-specific operations
32
- - Utility helpers for developing deterministic, deployable task logic
32
+ - Utility helpers for developing deterministic, deployable function logic
33
33
 
34
34
  ## Setup
35
35
 
@@ -50,17 +50,17 @@ $ yarn
50
50
 
51
51
  ## Usage
52
52
 
53
- Here’s an example of how to use the library in a Mimic task:
53
+ Here’s an example of how to use the library in a Mimic function:
54
54
 
55
55
  ```ts
56
- import { environment, Token } from '@mimicprotocol/lib-ts'
56
+ import { environment, ERC20Token } from '@mimicprotocol/lib-ts'
57
57
 
58
- const USDC = Token.fromString('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', 1)
58
+ const USDC = ERC20Token.fromString('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', 1)
59
59
 
60
- environment.getPrice(USDC, new Date(1744818017000))
60
+ environment.tokenPriceQuery(USDC, new Date(1744818017000))
61
61
  ```
62
62
 
63
- For full task development guide and examples please visit [docs.mimic.fi](https://docs.mimic.fi/)
63
+ For full function development guide and examples please visit [docs.mimic.fi](https://docs.mimic.fi/)
64
64
 
65
65
  ## Security
66
66
 
package/constants.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const RUNNER_TARGET_VERSION: string
package/constants.js ADDED
@@ -0,0 +1 @@
1
+ export const RUNNER_TARGET_VERSION = '0.0.1'
package/index.ts CHANGED
@@ -3,5 +3,8 @@ export * from './src/environment'
3
3
  export * from './src/evm'
4
4
  export * from './src/helpers'
5
5
  export * from './src/intents'
6
+ export * from './src/log'
7
+ export * from './src/storage'
8
+ export * from './src/svm'
6
9
  export * from './src/tokens'
7
10
  export * from './src/types'
package/package.json CHANGED
@@ -1,26 +1,40 @@
1
1
  {
2
2
  "name": "@mimicprotocol/lib-ts",
3
- "version": "0.0.1-rc.9",
3
+ "version": "0.0.1",
4
4
  "license": "GPL-3.0",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "build": "asc index.ts -b build/lib.wasm --disableWarning 235 --noEmit --transform json-as/transform",
9
9
  "test": "asp",
10
- "lint": "eslint . --ignore-pattern 'src/environment.ts' --ignore-pattern 'src/evm.ts'"
10
+ "lint": "eslint . --ignore-pattern 'src/environment.ts' --ignore-pattern 'src/evm.ts' --ignore-pattern 'src/svm.ts' --ignore-pattern 'src/log.ts'"
11
11
  },
12
12
  "files": [
13
13
  "src",
14
14
  "index.ts",
15
+ "constants.js",
16
+ "constants.d.ts",
15
17
  "asconfig.json"
16
18
  ],
19
+ "exports": {
20
+ ".": "./index.ts",
21
+ "./constants": {
22
+ "import": "./constants.js",
23
+ "require": "./constants.js",
24
+ "types": "./constants.d.ts"
25
+ }
26
+ },
17
27
  "devDependencies": {
18
28
  "@as-pect/cli": "8.1.0",
19
29
  "assemblyscript": "0.27.36"
20
30
  },
21
31
  "dependencies": {
22
- "eslint-config-mimic": "^0.0.3",
23
- "json-as": "1.0.7",
32
+ "as-base58": "^0.1.1",
33
+ "eslint-config-mimic": "^0.0.4",
34
+ "json-as": "1.1.7",
24
35
  "visitor-as": "0.11.4"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
25
39
  }
26
40
  }
@@ -0,0 +1,14 @@
1
+ import { ERC20Token } from '../tokens/ERC20Token'
2
+ import { ChainId } from '../types'
3
+
4
+ /* eslint-disable no-secrets/no-secrets */
5
+
6
+ export namespace Arbitrum {
7
+ export const CHAIN_ID = ChainId.ARBITRUM
8
+ export const ETH = ERC20Token.native(CHAIN_ID)
9
+ export const USDC = ERC20Token.fromString('0xaf88d065e77c8cC2239327C5EDb3A432268e5831', CHAIN_ID, 6, 'USDC')
10
+ export const USDT = ERC20Token.fromString('0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', CHAIN_ID, 6, 'USDT')
11
+ export const DAI = ERC20Token.fromString('0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', CHAIN_ID, 18, 'DAI')
12
+ export const WBTC = ERC20Token.fromString('0x2f2a2543b76a4166549f7aab2e75bef0aefc5b0f', CHAIN_ID, 8, 'WBTC')
13
+ export const WETH = ERC20Token.fromString('0x82af49447d8a07e3bd95bd0d56f35241523fbab1', CHAIN_ID, 18, 'WETH')
14
+ }
@@ -0,0 +1,15 @@
1
+ import { ERC20Token } from '../tokens'
2
+ import { ChainId } from '../types'
3
+
4
+ /* eslint-disable no-secrets/no-secrets */
5
+
6
+ export namespace Avalanche {
7
+ export const CHAIN_ID = ChainId.AVALANCHE
8
+ export const AVAX = ERC20Token.native(CHAIN_ID)
9
+ export const USDC = ERC20Token.fromString('0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E', CHAIN_ID, 6, 'USDC')
10
+ export const USDT = ERC20Token.fromString('0x9702230A8Ea53601f5cd2dc00fDbc13d4dF4A8c7', CHAIN_ID, 6, 'USDt')
11
+ export const DAI = ERC20Token.fromString('0xd586E7F844cEa2F87f50152665BCbc2C279D8d70', CHAIN_ID, 18, 'DAI.e')
12
+ export const WBTC = ERC20Token.fromString('0x50b7545627a5162F82A992c33b87aDc75187B218', CHAIN_ID, 8, 'WBTC.e')
13
+ export const WETH = ERC20Token.fromString('0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB', CHAIN_ID, 18, 'WETH.e')
14
+ export const WAVAX = ERC20Token.fromString('0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', CHAIN_ID, 18, 'WAVAX')
15
+ }
@@ -0,0 +1,15 @@
1
+ import { ERC20Token } from '../tokens'
2
+ import { ChainId } from '../types'
3
+
4
+ /* eslint-disable no-secrets/no-secrets */
5
+
6
+ export namespace BNB {
7
+ export const CHAIN_ID = ChainId.BNB
8
+ export const BNB = ERC20Token.native(CHAIN_ID)
9
+ export const USDC = ERC20Token.fromString('0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', CHAIN_ID, 18, 'USDC')
10
+ export const USDT = ERC20Token.fromString('0x55d398326f99059fF775485246999027B3197955', CHAIN_ID, 18, 'USDT')
11
+ export const DAI = ERC20Token.fromString('0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', CHAIN_ID, 18, 'DAI')
12
+ export const WBTC = ERC20Token.fromString('0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3ead9c', CHAIN_ID, 18, 'BTCB')
13
+ export const WETH = ERC20Token.fromString('0x2170Ed0880ac9A755fd29B2688956BD959F933F8', CHAIN_ID, 18, 'ETH')
14
+ export const WBNB = ERC20Token.fromString('0xBB4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', CHAIN_ID, 18, 'WBNB')
15
+ }
@@ -0,0 +1,14 @@
1
+ import { ERC20Token } from '../tokens'
2
+ import { ChainId } from '../types'
3
+
4
+ /* eslint-disable no-secrets/no-secrets */
5
+
6
+ export namespace Base {
7
+ export const CHAIN_ID = ChainId.BASE
8
+ export const ETH = ERC20Token.native(CHAIN_ID)
9
+ export const USDC = ERC20Token.fromString('0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', CHAIN_ID, 6, 'USDC')
10
+ export const USDT = ERC20Token.fromString('0xfde4c96c8593536e31f229ea8f37b2ada2699bb2', CHAIN_ID, 6, 'USDT')
11
+ export const DAI = ERC20Token.fromString('0x50c5725949a6f0c72e6c4a641f24049a917db0cb', CHAIN_ID, 18, 'DAI')
12
+ export const WBTC = ERC20Token.fromString('0x0555e30da8f98308edb960aa94c0db47230d2b9c', CHAIN_ID, 8, 'WBTC')
13
+ export const WETH = ERC20Token.fromString('0x4200000000000000000000000000000000000006', CHAIN_ID, 18, 'WETH')
14
+ }
@@ -0,0 +1,7 @@
1
+ import { ERC20Token } from '../tokens'
2
+ import { ChainId } from '../types'
3
+
4
+ export namespace BaseSepolia {
5
+ export const CHAIN_ID = ChainId.BASE_SEPOLIA
6
+ export const ETH = ERC20Token.native(CHAIN_ID)
7
+ }
@@ -1,12 +1,12 @@
1
- import { Token } from '../tokens'
1
+ import { ERC20Token } from '../tokens'
2
2
  import { ChainId } from '../types'
3
3
 
4
4
  export namespace Ethereum {
5
5
  export const CHAIN_ID = ChainId.ETHEREUM
6
- export const ETH = Token.native(CHAIN_ID)
7
- export const USDC = Token.fromString('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', CHAIN_ID, 6, 'USDC')
8
- export const USDT = Token.fromString('0xdac17f958d2ee523a2206206994597c13d831ec7', CHAIN_ID, 6, 'USDT')
9
- export const DAI = Token.fromString('0x6b175474e89094c44da98b954eedeac495271d0f', CHAIN_ID, 18, 'DAI')
10
- export const WBTC = Token.fromString('0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', CHAIN_ID, 8, 'WBTC')
11
- export const WETH = Token.fromString('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', CHAIN_ID, 18, 'WETH')
6
+ export const ETH = ERC20Token.native(CHAIN_ID)
7
+ export const USDC = ERC20Token.fromString('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', CHAIN_ID, 6, 'USDC')
8
+ export const USDT = ERC20Token.fromString('0xdac17f958d2ee523a2206206994597c13d831ec7', CHAIN_ID, 6, 'USDT')
9
+ export const DAI = ERC20Token.fromString('0x6b175474e89094c44da98b954eedeac495271d0f', CHAIN_ID, 18, 'DAI')
10
+ export const WBTC = ERC20Token.fromString('0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', CHAIN_ID, 8, 'WBTC')
11
+ export const WETH = ERC20Token.fromString('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', CHAIN_ID, 18, 'WETH')
12
12
  }
@@ -0,0 +1,14 @@
1
+ import { ERC20Token } from '../tokens'
2
+ import { ChainId } from '../types'
3
+
4
+ /* eslint-disable no-secrets/no-secrets */
5
+
6
+ export namespace Gnosis {
7
+ export const CHAIN_ID = ChainId.GNOSIS
8
+ export const xDAI = ERC20Token.native(CHAIN_ID)
9
+ export const USDC = ERC20Token.fromString('0x2a22f9c3b484c3629090feed35f17ff8f88f76f0', CHAIN_ID, 6, 'USDC')
10
+ export const USDT = ERC20Token.fromString('0x4ecaba5870353805a9f068101a40e0f32ed605c6', CHAIN_ID, 6, 'USDT')
11
+ export const WXDAI = ERC20Token.fromString('0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d', CHAIN_ID, 18, 'WXDAI')
12
+ export const WBTC = ERC20Token.fromString('0x8e5bbbb09ed1ebde8674cda39a0c169401db4252', CHAIN_ID, 8, 'WBTC')
13
+ export const WETH = ERC20Token.fromString('0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1', CHAIN_ID, 18, 'WETH')
14
+ }
@@ -1,12 +1,12 @@
1
- import { Token } from '../tokens'
1
+ import { ERC20Token } from '../tokens'
2
2
  import { ChainId } from '../types'
3
3
 
4
4
  export namespace Optimism {
5
5
  export const CHAIN_ID = ChainId.OPTIMISM
6
- export const ETH = Token.native(CHAIN_ID)
7
- export const USDC = Token.fromString('0x0b2c639c533813f4aa9d7837caf62653d097ff85', CHAIN_ID, 6, 'USDC')
8
- export const USDT = Token.fromString('0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', CHAIN_ID, 6, 'USDT')
9
- export const DAI = Token.fromString('0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', CHAIN_ID, 18, 'DAI')
10
- export const WBTC = Token.fromString('0x68f180fcce6836688e9084f035309e29bf0a2095', CHAIN_ID, 8, 'WBTC')
11
- export const WETH = Token.fromString('0x4200000000000000000000000000000000000006', CHAIN_ID, 18, 'WETH')
6
+ export const ETH = ERC20Token.native(CHAIN_ID)
7
+ export const USDC = ERC20Token.fromString('0x0b2c639c533813f4aa9d7837caf62653d097ff85', CHAIN_ID, 6, 'USDC')
8
+ export const USDT = ERC20Token.fromString('0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', CHAIN_ID, 6, 'USDT')
9
+ export const DAI = ERC20Token.fromString('0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', CHAIN_ID, 18, 'DAI')
10
+ export const WBTC = ERC20Token.fromString('0x68f180fcce6836688e9084f035309e29bf0a2095', CHAIN_ID, 8, 'WBTC')
11
+ export const WETH = ERC20Token.fromString('0x4200000000000000000000000000000000000006', CHAIN_ID, 18, 'WETH')
12
12
  }
@@ -1,12 +1,15 @@
1
- import { Token } from '../tokens'
1
+ import { ERC20Token } from '../tokens'
2
2
  import { ChainId } from '../types'
3
3
 
4
+ /* eslint-disable no-secrets/no-secrets */
5
+
4
6
  export namespace Polygon {
5
7
  export const CHAIN_ID = ChainId.POLYGON
6
- export const POL = Token.native(CHAIN_ID)
7
- export const USDC = Token.fromString('0x3c499c542cef5e3811e1192ce70d8cc03d5c3359', CHAIN_ID, 6, 'USDC')
8
- export const USDT = Token.fromString('0xc2132d05d31c914a87c6611c10748aeb04b58e8f', CHAIN_ID, 6, 'USDT')
9
- export const DAI = Token.fromString('0x8f3cf7ad23cd3cadbd9735aff958023239c6a063', CHAIN_ID, 18, 'DAI')
10
- export const WBTC = Token.fromString('0x1bfd67037b42cf73acf2047067bd4f2c47d9bfd6', CHAIN_ID, 8, 'WBTC')
11
- export const WETH = Token.fromString('0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', CHAIN_ID, 18, 'WETH')
8
+ export const POL = ERC20Token.native(CHAIN_ID)
9
+ export const USDC = ERC20Token.fromString('0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359', CHAIN_ID, 6, 'USDC')
10
+ export const USDT = ERC20Token.fromString('0xc2132D05D31c914a87C6611C10748AEb04B58e8F', CHAIN_ID, 6, 'USDT0')
11
+ export const DAI = ERC20Token.fromString('0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063', CHAIN_ID, 18, 'DAI')
12
+ export const WBTC = ERC20Token.fromString('0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6', CHAIN_ID, 8, 'WBTC')
13
+ export const WETH = ERC20Token.fromString('0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', CHAIN_ID, 18, 'WETH')
14
+ export const WPOL = ERC20Token.fromString('0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', CHAIN_ID, 18, 'WPOL')
12
15
  }
@@ -0,0 +1,13 @@
1
+ import { ERC20Token } from '../tokens'
2
+ import { ChainId } from '../types'
3
+
4
+ /* eslint-disable no-secrets/no-secrets */
5
+
6
+ export namespace Sonic {
7
+ export const CHAIN_ID = ChainId.SONIC
8
+ export const SONIC = ERC20Token.native(CHAIN_ID)
9
+ export const USDC = ERC20Token.fromString('0x29219dd400f2Bf60E5a23d13Be72B486D4038894', CHAIN_ID, 6, 'USDC')
10
+ export const USDT = ERC20Token.fromString('0x6047828dc181963ba44974801ff68e538da5eaf9', CHAIN_ID, 6, 'USDT')
11
+ export const WETH = ERC20Token.fromString('0x50c42dEAcD8Fc9773493ED674b675bE577f2634b', CHAIN_ID, 18, 'WETH')
12
+ export const WSONIC = ERC20Token.fromString('0x039e2fB66102314Ce7b64Ce5Ce3E5183bc94aD38', CHAIN_ID, 18, 'WSONIC')
13
+ }
@@ -1,3 +1,10 @@
1
+ export * from './Arbitrum'
2
+ export * from './Avalanche'
3
+ export * from './Base'
4
+ export * from './BaseSepolia'
5
+ export * from './BNB'
1
6
  export * from './Ethereum'
7
+ export * from './Gnosis'
2
8
  export * from './Optimism'
3
9
  export * from './Polygon'
10
+ export * from './Sonic'
@@ -1,29 +1,124 @@
1
- import { Address } from '../types'
1
+ import { evm } from '../evm'
2
+ import { Address, BigInt, ChainId, EvmDecodeParam, JSON } from '../types'
3
+ import { TriggerType } from '../types/TriggerType'
4
+
5
+ @json
6
+ export class SerializableSettler {
7
+ constructor(
8
+ public readonly address: string,
9
+ public readonly chainId: i32
10
+ ) {}
11
+ }
12
+
13
+ export class Settler {
14
+ constructor(
15
+ public readonly address: Address,
16
+ public readonly chainId: ChainId
17
+ ) {}
18
+
19
+ static fromSerializable(serializable: SerializableSettler): Settler {
20
+ return new Settler(Address.fromString(serializable.address), serializable.chainId)
21
+ }
22
+ }
23
+
24
+ @json
25
+ export class SerializableTriggerPayload {
26
+ constructor(
27
+ public type: u8,
28
+ public data: string
29
+ ) {}
30
+ }
31
+
32
+ export class EventTriggerPayloadData {
33
+ constructor(
34
+ public chainId: BigInt,
35
+ public blockHash: string,
36
+ public index: BigInt,
37
+ public contract: Address,
38
+ public topics: string[],
39
+ public eventData: string
40
+ ) {}
41
+ }
42
+
43
+ @json
44
+ export class TriggerPayload {
45
+ constructor(
46
+ public type: TriggerType,
47
+ public data: string
48
+ ) {}
49
+
50
+ static fromSerializable(serializable: SerializableTriggerPayload): TriggerPayload {
51
+ return new TriggerPayload(serializable.type, serializable.data)
52
+ }
53
+
54
+ getCronData(): BigInt {
55
+ if (this.type !== TriggerType.CRON) throw new Error("Can't get cron data, config type is not cron")
56
+ return TriggerPayload.deserializeCronTriggerPayloadData(this.data)
57
+ }
58
+
59
+ getEventData(): EventTriggerPayloadData {
60
+ if (this.type !== TriggerType.EVENT) throw new Error("Can't get event data, config type is not event")
61
+ return TriggerPayload.deserializeEventTriggerPayloadData(this.data)
62
+ }
63
+
64
+ static deserializeCronTriggerPayloadData(data: string): BigInt {
65
+ return BigInt.fromString(evm.decode(new EvmDecodeParam('uint256', data)))
66
+ }
67
+
68
+ static deserializeEventTriggerPayloadData(data: string): EventTriggerPayloadData {
69
+ const fields = JSON.parse<string[]>(
70
+ evm.decode(new EvmDecodeParam('(uint256,bytes32,uint256,address,bytes32[],bytes)', data))
71
+ )
72
+ return new EventTriggerPayloadData(
73
+ BigInt.fromString(fields[0]),
74
+ fields[1],
75
+ BigInt.fromString(fields[2]),
76
+ Address.fromString(fields[3]),
77
+ JSON.parse<string[]>(fields[4]),
78
+ fields[5]
79
+ )
80
+ }
81
+ }
2
82
 
3
83
  @json
4
84
  export class SerializableContext {
5
85
  constructor(
6
86
  public readonly timestamp: u64,
87
+ public readonly consensusThreshold: u8,
7
88
  public user: string,
8
- public settler: string,
9
- public configId: string
89
+ public settlers: SerializableSettler[],
90
+ public triggerSig: string,
91
+ public triggerPayload: SerializableTriggerPayload
10
92
  ) {}
11
93
  }
12
94
 
13
95
  export class Context {
14
96
  constructor(
15
97
  public readonly timestamp: u64,
98
+ public readonly consensusThreshold: u8,
16
99
  public user: Address,
17
- public settler: Address,
18
- public configId: string
100
+ public settlers: Settler[],
101
+ public triggerSig: string,
102
+ public triggerPayload: TriggerPayload
19
103
  ) {}
20
104
 
21
105
  static fromSerializable(serializable: SerializableContext): Context {
22
106
  return new Context(
23
107
  serializable.timestamp,
108
+ serializable.consensusThreshold,
24
109
  Address.fromString(serializable.user),
25
- Address.fromString(serializable.settler),
26
- serializable.configId
110
+ serializable.settlers.map<Settler>((s) => Settler.fromSerializable(s)),
111
+ serializable.triggerSig,
112
+ TriggerPayload.fromSerializable(serializable.triggerPayload)
27
113
  )
28
114
  }
115
+
116
+ findSettler(chainId: ChainId): Address {
117
+ for (let i = 0; i < this.settlers.length; i++) {
118
+ if (this.settlers[i].chainId === chainId) {
119
+ return this.settlers[i].address
120
+ }
121
+ }
122
+ throw new Error(`Settler not found for chainId: ${chainId}`)
123
+ }
29
124
  }