Safe-Module-Template Configuration Guide
Safe-Module-Template is a tool for configuring smart contract templates. Here are the steps to configure a template:
Step 1: Import Necessary Libraries and Tools
At the beginning of the file, we need to import some necessary libraries and tools. For example, we need the ChainId, Comparison and Template types, and the generateUniqueId function.
import { Template, ChainId, Comparison } from '@/typings'
import { generateUniqueId } from '@/utils'
Step 2: Create Template Object
Next, we need to create a template object. This object needs to include the following properties:
Parameter | Type | Required | Description |
---|
id | String | Yes | The unique identifier of the template, which can be generated using the generateUniqueId function. |
chainId | ChainId | Yes | The ID of the chain, such as ChainId.ARBITRUM. |
templateName | String | Yes | The name of the template. |
contractAddress | String | Yes | The address of the smart contract. |
functionsConfig | Array | Yes | An array of function configurations. |
export const uniExactInputSingleTemplate: Template = {
id: generateUniqueId(),
chainId: ChainId.POLYGON,
templateName: 'Uniswap V3 Router2 ExactInputSingle',
contractAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
functionsConfig: [],
}
Step 3: Configure Functions
In the functionsConfig array, we need to configure an object for each function. This object needs to include the following properties:
Parameter | Type | Required | Description | Nested Parameters |
---|
sighash | String | Yes | The signature hash of the function. | - |
ethValue | Object | No | The signature hash of the function. | Parmeter | Type | Required | Description | Nested Parameters |
---|
value | String | No | The current value of ethValue. | - | comparison | Comparison | No | The current operator of ethValue, currently only supports Comparison.Eq (equal to). | - |
|
params | Array | No | The parameter array of the current function. | Parmeter | Type | Required | Description | Nested Parameters |
---|
index | Number | Yes | The index of the parameter. | - | autoFillingSafeAddress | Boolean | No | Whether to automatically fill in the safe address. | - | require | Boolean | No | Is it necessary to fill in? If true, the UI page will prompt in red, if false, it will prompt in yellow. If this field is not filled in, there will be no prompt. | - | value | String | No | What is the value of the current parameter | - | comparison | Comparison | No | Current parameter operator. There are three types of operators in total" are Comparison.Eq (equal to), Comparison.Lte (less than or equal to), and Comparison.Gte (greater than or equal to). | - | params | Boolean | No | This field is only used when there is a tuple type in the current function parameters. The parameters in the array are the same as the parent params. | The parameters in the array are the same as the parent params. |
|
const functionsConfig = [
{
sighash: '0x04e45aaf',
params:[
{
index: 0,
params:[
{
index: 3,
require: true,
autoFillingSafeAddress: true,
}
]
}
]
}
]
export const uniExactInputSingleTemplate: Template = {
id: generateUniqueId(),
chainId: ChainId.POLYGON,
templateName: 'Uniswap V3 Router2 ExactInputSingle',
contractAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
functionsConfig: functionsConfig,
}
Complete Example
import { Template, ChainId, Comparison } from '@/typings'
import { generateUniqueId } from '@/utils'
export const uniExactInputSingleTemplate: Template = {
id: generateUniqueId(),
chainId: ChainId.POLYGON,
templateName: 'Uniswap V3 Router2 ExactInputSingle',
contractAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45',
functionsConfig: [
{
sighash: '0x04e45aaf',
params: [
{
index: 0,
params: [
{
index: 0,
require: true,
comparison: Comparison.Eq,
},
{
index: 1,
require: true,
comparison: Comparison.Eq,
},
{
index: 2,
require: true,
comparison: Comparison.Eq,
},
{
index: 3,
require: true,
comparison: Comparison.Eq,
autoFillingSafeAddress: true,
},
],
},
],
},
],
}