@mimicprotocol/lib-ts 0.0.1-rc.35 → 0.0.1-rc.36
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 +6 -0
- package/README.md +4 -4
- package/package.json +1 -1
- package/src/context/Context.ts +19 -19
- package/src/environment.ts +1 -1
- package/src/intents/Intent.ts +1 -1
package/CHANGELOG.md
CHANGED
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
|
|
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
|
|
32
|
+
- Utility helpers for developing deterministic, deployable function logic
|
|
33
33
|
|
|
34
34
|
## Setup
|
|
35
35
|
|
|
@@ -50,7 +50,7 @@ $ yarn
|
|
|
50
50
|
|
|
51
51
|
## Usage
|
|
52
52
|
|
|
53
|
-
Here’s an example of how to use the library in a Mimic
|
|
53
|
+
Here’s an example of how to use the library in a Mimic function:
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
56
|
import { environment, ERC20Token } from '@mimicprotocol/lib-ts'
|
|
@@ -60,7 +60,7 @@ const USDC = ERC20Token.fromString('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
|
60
60
|
environment.tokenPriceQuery(USDC, new Date(1744818017000))
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
For full
|
|
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/package.json
CHANGED
package/src/context/Context.ts
CHANGED
|
@@ -22,14 +22,14 @@ export class Settler {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
@json
|
|
25
|
-
export class
|
|
25
|
+
export class SerializableTriggerPayload {
|
|
26
26
|
constructor(
|
|
27
27
|
public type: u8,
|
|
28
28
|
public data: string
|
|
29
29
|
) {}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export class
|
|
32
|
+
export class EventTriggerPayloadData {
|
|
33
33
|
constructor(
|
|
34
34
|
public chainId: BigInt,
|
|
35
35
|
public blockHash: string,
|
|
@@ -41,35 +41,35 @@ export class EventTriggerData {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
@json
|
|
44
|
-
export class
|
|
44
|
+
export class TriggerPayload {
|
|
45
45
|
constructor(
|
|
46
46
|
public type: TriggerType,
|
|
47
47
|
public data: string
|
|
48
48
|
) {}
|
|
49
49
|
|
|
50
|
-
static fromSerializable(serializable:
|
|
51
|
-
return new
|
|
50
|
+
static fromSerializable(serializable: SerializableTriggerPayload): TriggerPayload {
|
|
51
|
+
return new TriggerPayload(serializable.type, serializable.data)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
getCronData(): BigInt {
|
|
55
|
-
if (this.type !== TriggerType.CRON) throw new Error("Can't get cron data,
|
|
56
|
-
return
|
|
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
57
|
}
|
|
58
58
|
|
|
59
|
-
getEventData():
|
|
60
|
-
if (this.type !== TriggerType.EVENT) throw new Error("Can't get event data,
|
|
61
|
-
return
|
|
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
62
|
}
|
|
63
63
|
|
|
64
|
-
static
|
|
64
|
+
static deserializeCronTriggerPayloadData(data: string): BigInt {
|
|
65
65
|
return BigInt.fromString(evm.decode(new EvmDecodeParam('uint256', data)))
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
static
|
|
68
|
+
static deserializeEventTriggerPayloadData(data: string): EventTriggerPayloadData {
|
|
69
69
|
const fields = JSON.parse<string[]>(
|
|
70
70
|
evm.decode(new EvmDecodeParam('(uint256,bytes32,uint256,address,bytes32[],bytes)', data))
|
|
71
71
|
)
|
|
72
|
-
return new
|
|
72
|
+
return new EventTriggerPayloadData(
|
|
73
73
|
BigInt.fromString(fields[0]),
|
|
74
74
|
fields[1],
|
|
75
75
|
BigInt.fromString(fields[2]),
|
|
@@ -87,8 +87,8 @@ export class SerializableContext {
|
|
|
87
87
|
public readonly consensusThreshold: u8,
|
|
88
88
|
public user: string,
|
|
89
89
|
public settlers: SerializableSettler[],
|
|
90
|
-
public
|
|
91
|
-
public
|
|
90
|
+
public triggerSig: string,
|
|
91
|
+
public triggerPayload: SerializableTriggerPayload
|
|
92
92
|
) {}
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -98,8 +98,8 @@ export class Context {
|
|
|
98
98
|
public readonly consensusThreshold: u8,
|
|
99
99
|
public user: Address,
|
|
100
100
|
public settlers: Settler[],
|
|
101
|
-
public
|
|
102
|
-
public
|
|
101
|
+
public triggerSig: string,
|
|
102
|
+
public triggerPayload: TriggerPayload
|
|
103
103
|
) {}
|
|
104
104
|
|
|
105
105
|
static fromSerializable(serializable: SerializableContext): Context {
|
|
@@ -108,8 +108,8 @@ export class Context {
|
|
|
108
108
|
serializable.consensusThreshold,
|
|
109
109
|
Address.fromString(serializable.user),
|
|
110
110
|
serializable.settlers.map<Settler>((s) => Settler.fromSerializable(s)),
|
|
111
|
-
serializable.
|
|
112
|
-
|
|
111
|
+
serializable.triggerSig,
|
|
112
|
+
TriggerPayload.fromSerializable(serializable.triggerPayload)
|
|
113
113
|
)
|
|
114
114
|
}
|
|
115
115
|
|
package/src/environment.ts
CHANGED
|
@@ -197,7 +197,7 @@ export namespace environment {
|
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
199
|
* Returns the current execution context containing environment information.
|
|
200
|
-
* @returns The Context object containing: user, settler, timestamp, and
|
|
200
|
+
* @returns The Context object containing: user, settler, timestamp, consensusThreshold and triggerPayload
|
|
201
201
|
*/
|
|
202
202
|
export function getContext(): Context {
|
|
203
203
|
const context = JSON.parse<SerializableContext>(_getContext())
|
package/src/intents/Intent.ts
CHANGED
|
@@ -239,7 +239,7 @@ export abstract class Intent {
|
|
|
239
239
|
this.events = events || []
|
|
240
240
|
this.nonce = nonce
|
|
241
241
|
? nonce
|
|
242
|
-
: evm.keccak(`${context.
|
|
242
|
+
: evm.keccak(`${context.triggerSig}${context.timestamp}${context.triggerPayload.data}${++INTENT_INDEX}`)
|
|
243
243
|
|
|
244
244
|
if (!this.user || this.user == NULL_ADDRESS) throw new Error('A user must be specified')
|
|
245
245
|
if (!this.settler || this.settler == NULL_ADDRESS) throw new Error('A settler contract must be specified')
|