diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..91a9298 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,38 @@ +name: "CI" + +on: + push: + branches: + - main + pull_request: + +env: + GO_VERSION: 1.24.0 + +jobs: + test-go: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + + - name: Check go mod + run: | + go mod tidy + git diff --exit-code go.mod + + - name: Build examples + run: go install ./... + + - name: Lint + uses: golangci/golangci-lint-action@v7.0.0 + with: + version: latest + skip-build-cache: true + skip-pkg-cache: true \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..f51cf5b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,158 @@ +version: "2" +run: + issues-exit-code: 1 + tests: true +output: + formats: + text: + path: stdout + print-linter-name: true + print-issued-lines: true +linters: + enable: + - bidichk + - bodyclose + - copyloopvar + - dogsled + - durationcheck + - err113 + - gocritic + - godot + - goprintffuncname + - importas + - makezero + - misspell + - nakedret + - nilerr + - noctx + - revive + - unconvert + - usetesting + - wastedassign + disable: + - asciicheck + - containedctx + - contextcheck + - cyclop + - decorder + - depguard + - dupl + - errchkjson + - errname + - exhaustive + - forbidigo + - funlen + - gocognit + - goconst + - gocyclo + - godox + - goheader + - gomoddirectives + - gomodguard + - gosec + - grouper + - ireturn + - lll + - maintidx + - nlreturn + - nolintlint + - paralleltest + - predeclared + - promlinter + - rowserrcheck + - sqlclosecheck + - staticcheck + - tagliatelle + - testpackage + - thelper + - tparallel + - unused + - varnamelen + - wrapcheck + - wsl + settings: + dogsled: + max-blank-identifiers: 3 + dupl: + threshold: 150 + errcheck: + check-type-assertions: false + check-blank: false + goconst: + min-len: 3 + min-occurrences: 3 + gocritic: + disabled-checks: + - ifElseChain + gocyclo: + min-complexity: 10 + lll: + line-length: 140 + tab-width: 1 + misspell: + ignore-rules: + - sucess + nakedret: + max-func-lines: 30 + prealloc: + simple: true + range-loops: true + for-loops: false + exclusions: + generated: lax + rules: + - linters: + - err113 + text: do not define dynamic errors + - linters: + - revive + text: if-return + - linters: + - revive + text: var-naming + - linters: + - revive + text: error-return + - linters: + - revive + text: package-comments + - linters: + - revive + text: superfluous-else + - linters: + - revive + text: indent-error-flow + - linters: + - revive + text: unused-parameter + - linters: + - revive + text: empty-block + - linters: + - revive + text: redefines-builtin-id + paths: + - .*\.pb\.go$ + - third_party$ + - builtin$ + - examples$ +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + new: false +formatters: + enable: + - gofmt + settings: + gofmt: + simplify: true + goimports: + local-prefixes: + - github.com/BoostyLabs/hotpot-sdk-go + exclusions: + generated: lax + paths: + - .*\.pb\.go$ + - third_party$ + - builtin$ + - examples$ \ No newline at end of file diff --git a/client/intents.go b/client/intents.go index 7205823..de32a07 100644 --- a/client/intents.go +++ b/client/intents.go @@ -29,6 +29,7 @@ type CreateIntentResponse struct { types.ApprovalToSign } +// UnmarshalJSON implements json.Unmarshaler interface. func (resp *CreateIntentResponse) UnmarshalJSON(data []byte) error { type createIntentResponseCodec struct { ID uuid.UUID `json:"intent_id"` @@ -63,6 +64,7 @@ func (resp *CreateIntentResponse) UnmarshalJSON(data []byte) error { } } +// CreateIntent creates a new intent using the provided request data and returns the created intent details or an error. func (c *Client) CreateIntent(ctx context.Context, req CreateIntentRequest) (CreateIntentResponse, error) { var resp = CreateIntentResponse{} var endpoint = c.buildURL("intents") diff --git a/client/quotes.go b/client/quotes.go index 818b964..193642f 100644 --- a/client/quotes.go +++ b/client/quotes.go @@ -21,6 +21,7 @@ type GetTheBestQuoteRequest struct { AffiliateFees map[string]RequestedFee `json:"affiliate_fees"` } +// RequestedFee represents the fee requested for the swap. type RequestedFee struct { FeeBps *types.Int `json:"fee_bps"` NetworkID uint64 `json:"network_id"` diff --git a/crypto/evm/permit2.go b/crypto/evm/permit2.go index e8bfee4..820d9ee 100644 --- a/crypto/evm/permit2.go +++ b/crypto/evm/permit2.go @@ -182,7 +182,7 @@ func GetPermit2Signature(digest []byte, sign func([]byte) ([]byte, error)) (sig } // Normalize to 27/28 for EVM contracts if needed - sig[64] = sig[64] + 27 + sig[64] += 27 return sig, nil } diff --git a/types/approvals.go b/types/approvals.go index e7a1c64..00423e7 100644 --- a/types/approvals.go +++ b/types/approvals.go @@ -103,6 +103,7 @@ func NewCosignIntentApproval(transaction string, userAddress string) IntentAppro } } +// MarshalJSON implements json.Marshaler interface. func (a *IntentApproval) MarshalJSON() ([]byte, error) { var v = addIntentApprovalRequestCodec{Type: string(a.approvalMechanism)} switch { diff --git a/types/bigint.go b/types/bigint.go index 67d38c9..2740d00 100644 --- a/types/bigint.go +++ b/types/bigint.go @@ -30,6 +30,7 @@ func NewIntFromPercent(percent float64) (*Int, error) { return NewInt(int64(math.Round(percent * PercentToBps))), nil } +// MarshalJSON implements the json.Marshaler interface. func (i *Int) MarshalJSON() ([]byte, error) { buf := new(bytes.Buffer) buf.WriteByte('"') @@ -38,6 +39,7 @@ func (i *Int) MarshalJSON() ([]byte, error) { return buf.Bytes(), nil } +// UnmarshalJSON implements the json.Unmarshaler interface. func (i *Int) UnmarshalJSON(b []byte) error { b = bytes.Trim(b, `"`) return i.Int.UnmarshalJSON(b) diff --git a/types/networks.go b/types/networks.go index 9a1d59b..ea99766 100644 --- a/types/networks.go +++ b/types/networks.go @@ -1,5 +1,6 @@ package types +// Network represents the network entity data. type Network struct { ID int64 `json:"id"` Name string `json:"name"` diff --git a/types/quotes.go b/types/quotes.go index 53a6c8f..d022a59 100644 --- a/types/quotes.go +++ b/types/quotes.go @@ -47,6 +47,7 @@ const ( DepositTypeDirect DepositType = "direct" ) +// EstimatedFee represents the estimated fee for a specific token. type EstimatedFee struct { FeeBps *Int `json:"fee_bps"` NetworkID uint64 `json:"network_id"`