Skip to content

Commit

Permalink
add Decimals field to payment settings (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk authored Jan 22, 2025
1 parent 803f11f commit bc98cc4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
3 changes: 3 additions & 0 deletions internal/payments/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type PaymentOptionConfig struct {
Type protocol.PaymentRequestType
ContractAddress common.Address
Features []protocol.PaymentFeatures `json:"features,omitempty"`
Decimals int
}

// configDTO is the data transfer object for the configuration. It maps to payment configuration file
Expand All @@ -53,6 +54,7 @@ type paymentOptionConfigDTO struct {
Type protocol.PaymentRequestType `yaml:"Type" json:"type"`
ContractAddress string `yaml:"ContractAddress,omitempty" json:"contractAddress,omitempty"`
Features []string `yaml:"Features,omitempty" json:"features,omitempty"`
Decimals int `yaml:"Decimals" json:"decimals"`
}

// CustomDecoder wraps yaml.Decoder to add custom functionality
Expand Down Expand Up @@ -107,6 +109,7 @@ func (d *configDecoder) Decode() (*Config, error) {
Type: option.Type,
ContractAddress: common.HexToAddress(option.ContractAddress),
Features: features,
Decimals: option.Decimals,
},
}
}
Expand Down
13 changes: 11 additions & 2 deletions internal/payments/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestSettingsFromConfig(t *testing.T) {
Type: protocol.Iden3PaymentRailsRequestV1Type,
ContractAddress: ethCommon.HexToAddress(""),
Features: nil,
Decimals: 18,
},
},
2: ChainConfig{
Expand All @@ -39,8 +40,9 @@ func TestSettingsFromConfig(t *testing.T) {
PaymentOption: PaymentOptionConfig{
Name: "Amoy USDT",
Type: protocol.Iden3PaymentRailsERC20RequestV1Type,
ContractAddress: ethCommon.HexToAddress("0x2FE40749812FAC39a0F380649eF59E01bccf3a1A"),
ContractAddress: ethCommon.HexToAddress("0x71dcc8Dc5Eb138003d3571255458Bc5692a60eD4"),
Features: nil,
Decimals: 6,
},
},
3: ChainConfig{
Expand All @@ -49,8 +51,9 @@ func TestSettingsFromConfig(t *testing.T) {
PaymentOption: PaymentOptionConfig{
Name: "Amoy USDC",
Type: protocol.Iden3PaymentRailsERC20RequestV1Type,
ContractAddress: ethCommon.HexToAddress("0x2FE40749812FAC39a0F380649eF59E01bccf3a1A"),
ContractAddress: ethCommon.HexToAddress("0x71dcc8Dc5Eb138003d3571255458Bc5692a60eD4"),
Features: []protocol.PaymentFeatures{"EIP-2612"},
Decimals: 6,
},
},
4: ChainConfig{
Expand All @@ -61,6 +64,7 @@ func TestSettingsFromConfig(t *testing.T) {
Type: protocol.Iden3PaymentRailsRequestV1Type,
ContractAddress: ethCommon.HexToAddress(""),
Features: nil,
Decimals: 18,
},
},
5: ChainConfig{
Expand All @@ -71,6 +75,7 @@ func TestSettingsFromConfig(t *testing.T) {
Type: protocol.Iden3PaymentRailsERC20RequestV1Type,
ContractAddress: ethCommon.HexToAddress("0xb0101c1Ffdd1213B886FebeF6F07442e48990c9C"),
Features: nil,
Decimals: 18,
},
},
6: ChainConfig{
Expand All @@ -81,6 +86,7 @@ func TestSettingsFromConfig(t *testing.T) {
Type: protocol.Iden3PaymentRailsERC20RequestV1Type,
ContractAddress: ethCommon.HexToAddress("0xb0101c1Ffdd1213B886FebeF6F07442e48990c9C"),
Features: []protocol.PaymentFeatures{"EIP-2612"},
Decimals: 18,
},
},
7: ChainConfig{
Expand All @@ -91,6 +97,7 @@ func TestSettingsFromConfig(t *testing.T) {
Type: protocol.Iden3PaymentRailsRequestV1Type,
ContractAddress: ethCommon.HexToAddress(""),
Features: nil,
Decimals: 18,
},
},
8: ChainConfig{
Expand All @@ -101,6 +108,7 @@ func TestSettingsFromConfig(t *testing.T) {
Type: protocol.Iden3PaymentRailsERC20RequestV1Type,
ContractAddress: ethCommon.HexToAddress("0x986caE6ADcF5da2a1514afc7317FBdeE0B4048Db"),
Features: nil,
Decimals: 18,
},
},
9: ChainConfig{
Expand All @@ -111,6 +119,7 @@ func TestSettingsFromConfig(t *testing.T) {
Type: protocol.Iden3PaymentRailsERC20RequestV1Type,
ContractAddress: ethCommon.HexToAddress("0x986caE6ADcF5da2a1514afc7317FBdeE0B4048Db"),
Features: []protocol.PaymentFeatures{"EIP-2612"},
Decimals: 18,
},
},
}
Expand Down
14 changes: 12 additions & 2 deletions internal/payments/testdata/payment_settings.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,59 @@
- ID: 1
Name: AmoyNative
Type: Iden3PaymentRailsRequestV1
Decimals: 18
- ID: 2
Name: Amoy USDT
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0x2FE40749812FAC39a0F380649eF59E01bccf3a1A
ContractAddress: 0x71dcc8Dc5Eb138003d3571255458Bc5692a60eD4
Features: []
Decimals: 6
- ID: 3
Name: Amoy USDC
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0x2FE40749812FAC39a0F380649eF59E01bccf3a1A
ContractAddress: 0x71dcc8Dc5Eb138003d3571255458Bc5692a60eD4
Features:
- EIP-2612
Decimals: 6
59141:
PaymentRails: 0x40E3EF221AA93F6Fe997c9b0393322823Bb207d3
PaymentOptions:
- ID: 4
Name: LineaSepoliaNative
Type: Iden3PaymentRailsRequestV1
Decimals: 18
- ID: 5
Name: Linea Sepolia USDT
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0xb0101c1Ffdd1213B886FebeF6F07442e48990c9C
Features: []
Decimals: 18
- ID: 6
Name: Linea Sepolia USDC
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0xb0101c1Ffdd1213B886FebeF6F07442e48990c9C
Features:
- EIP-2612
Decimals: 18
2442:
PaymentRails: 0x09c269e74d8B47c98537Acd6CbEe8056806F4c70
PaymentOptions:
- ID: 7
Name: ZkEvmNative
Type: Iden3PaymentRailsRequestV1
Decimals: 18
- ID: 8
Name: ZkEvm USDT
Type: Iden3PaymentRailsERC20RequestV1
Currency: USDT
ContractAddress: 0x986caE6ADcF5da2a1514afc7317FBdeE0B4048Db
Features: []
Decimals: 18
- ID: 9
Name: ZkEvm USDC
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0x986caE6ADcF5da2a1514afc7317FBdeE0B4048Db
Features:
- EIP-2612
Decimals: 18

13 changes: 11 additions & 2 deletions payment_settings.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,59 @@
- ID: 1
Name: AmoyNative
Type: Iden3PaymentRailsRequestV1
Decimals: 18
- ID: 2
Name: Amoy USDT
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0x2FE40749812FAC39a0F380649eF59E01bccf3a1A
ContractAddress: 0x71dcc8Dc5Eb138003d3571255458Bc5692a60eD4
Features: []
Decimals: 6
- ID: 3
Name: Amoy USDC
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0x2FE40749812FAC39a0F380649eF59E01bccf3a1A
ContractAddress: 0x71dcc8Dc5Eb138003d3571255458Bc5692a60eD4
Features:
- EIP-2612
Decimals: 6
59141:
PaymentRails: 0x40E3EF221AA93F6Fe997c9b0393322823Bb207d3
PaymentOptions:
- ID: 4
Name: LineaSepoliaNative
Type: Iden3PaymentRailsRequestV1
Decimals: 18
- ID: 5
Name: Linea Sepolia USDT
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0xb0101c1Ffdd1213B886FebeF6F07442e48990c9C
Features: []
Decimals: 18
- ID: 6
Name: Linea Sepolia USDC
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0xb0101c1Ffdd1213B886FebeF6F07442e48990c9C
Features:
- EIP-2612
Decimals: 18
2442:
PaymentRails: 0x09c269e74d8B47c98537Acd6CbEe8056806F4c70
PaymentOptions:
- ID: 7
Name: ZkEvmNative
Type: Iden3PaymentRailsRequestV1
Decimals: 18
- ID: 8
Name: ZkEvm USDT
Type: Iden3PaymentRailsERC20RequestV1
Currency: USDT
ContractAddress: 0x986caE6ADcF5da2a1514afc7317FBdeE0B4048Db
Features: []
Decimals: 18
- ID: 9
Name: ZkEvm USDC
Type: Iden3PaymentRailsERC20RequestV1
ContractAddress: 0x986caE6ADcF5da2a1514afc7317FBdeE0B4048Db
Features:
- EIP-2612
Decimals: 18

0 comments on commit bc98cc4

Please sign in to comment.